package com.sgj.service.impl;

import com.sgj.mapper.StuMapper;
import com.sgj.pojo.Stu;
import com.sgj.service.StuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author 沈国纪
 * @date 2021/7/5 18:04
 */
@Service
public class StuServiceImpl implements StuService {

	@Resource
	private StuMapper stuMapper;

	@Transactional(propagation = Propagation.SUPPORTS)
	@Override
	public Stu getStuInfo(int id) {
		return stuMapper.selectByPrimaryKey(id);
	}

	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public void saveStu(Stu stu) {
		stuMapper.insert(stu);
	}

	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public void updateStu(Stu stu) {
		stuMapper.updateByPrimaryKey(stu);
	}

	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public void deleteStu(int id) {
		stuMapper.deleteByPrimaryKey(id);
	}
}